<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>我的</title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
	<link href="../css/mui.css" rel="stylesheet"/>
	<link href="../css/mui.min.css" rel="stylesheet"/>
	<link href="../css/mui-icons-extra.css" rel="stylesheet"/>
	<link href="../css/app.css" rel="stylesheet"/>
	<style type="text/css">
		.hr {
			width: 100%;
			height: 20px;
			background: #F0F0F0;
			border: 0;
		}
	</style>
</head>
<body>
	<!-- 头部TITLE -->
	<div class="app-my">
		<div class="app-my-bg" id="uHeadBg">
			<img src="../imgs/tmp2.png">
		</div>
		<table class="app-my-title">
			<tr>
				<td class="app-title-img" id="uHead" 
						onclick="choosePhoto(this)">
					<img src="../imgs/tmp2.png">
				</td>
				<td>
					<div class="app-signature">
					<b id="uname">昵称</b>
					<p id="udetail">个人签名</p>
				</td>
				<td>
					<div class="app-my-set app-heart-blue" 
						onclick="jumpToMyset()">
						<b>设置</b>
						<span class="mui-icon mui-icon-gear"></span>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<!-- <textarea id="path"></textarea> -->
	<!-- 头部TITLE -->
	
	<!-- 主体部分 -->
	<!-- 点赞/收藏/创单 -->
	<ul class="mui-table-view">
		<li class="mui-table-view-cell" 
			onclick="jumpToMyZanList()">
			<a class="mui-navigate-right">
				我的点赞
				<span class="mui-icon-extra mui-icon-extra-heart-filled app-heart-light"></span>
				<span class="app-list-right">
					<p class="app-heart-light" id="zanTotal">0</p>
				</span>
			</a>
		</li>
		<li class="mui-table-view-cell" 
			onclick="jumpToMyCollectList()">
			<a class="mui-navigate-right">
				我的收藏
				<span class="mui-icon mui-icon-starhalf app-heart-light"></span>
				<span class="app-list-right">
					<p class="app-heart-light" id="collectTotal">0</p>
				</span>
			</a>
		</li>
<!-- 		<li class="mui-table-view-cell" 
			onclick="jumpToMySignList()">
			<a class="mui-navigate-right">
				我的签到
				<span class="mui-icon mui-icon-location app-heart-light"></span>
				<span class="app-list-right">
					<p class="app-heart-light" id="signTotal">0</p>
				</span>
			</a>
		</li> -->
	</ul>
	<!-- 点赞/收藏/创单 -->
	<!-- 空行 -->
	<div class="hr"></div>
	<!-- 空行 -->
	<!-- 创作过程 -->
	<ul class="mui-table-view">
		<li class="mui-table-view-cell" 
			onclick="jumpToMyPlusList()">
			<a class="mui-navigate-right">
				加入创单
				<span class="mui-icon mui-icon-plus app-heart-light"></span>
				<span class="app-list-right">
					<p class="app-heart-light" id="plusTotal">0</p>
				</span>
			</a>
		</li>
		<li class="mui-table-view-cell">
			<a class="mui-navigate-right">
				 我的创板
				 <span class="mui-icon mui-icon-pengyouquan app-heart-light"></span>
			</a>
		</li>
		<li class="mui-table-view-cell">
			<a class="mui-navigate-right">
				 我的作品
				 <span class="mui-icon-extra mui-icon-extra-cart app-heart-light"></span>
			</a>
		</li>
	</ul>
	<!-- 创作过程 -->
	<!-- 空行 -->
	<div class="hr"></div>
	<!-- 空行 -->
	<!-- 我的财务 -->
	<ul class="mui-table-view">
		<li class="mui-table-view-cell">
			<a class="mui-navigate-right">
				 我的金币
				 <span class="mui-icon-extra mui-icon-extra-gold app-heart-light"></span>
			</a>
		</li>
	</ul>
	<!-- 我的财务 -->
	<!-- 空行 -->
	<div class="hr"></div>
	<!-- 空行 -->
	<!-- 我的财务 -->
	<!-- 关于应用 -->
	<ul class="mui-table-view">
		<li class="mui-table-view-cell" onclick="setSign()">
			<a class="mui-navigate-right">
				 我的签到
				 <span class="mui-icon mui-icon-location app-heart-light"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" 
			onclick="jumpToMyOpinionList()">
			<a class="mui-navigate-right">
				 有奖建议
				 <span class="mui-icon mui-icon-compose app-heart-light"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" onclick="jumpToMyHelp()">
			<a class="mui-navigate-right">
				 使用帮助
				 <span class="mui-icon mui-icon-help app-heart-light"></span>
			</a>
		</li>
	</ul>
	<!-- 关于应用 -->
	<!-- 空行 -->
	<div class="hr"></div>
	<br><br><br>
	<textarea rows="5" id="pathUrl"></textarea>
	<div class="hr"></div>
	<br><br><br>
	<!-- 空行 -->
	<!-- 主体部分 -->
	
	<!-- 底部菜单 -->
	<nav class="mui-bar mui-bar-tab">
		<a class="mui-tab-item" onclick="jumpToIndex()">
			<span class="mui-icon mui-icon-home"></span>
			<span class="mui-tab-label">首页</span>
		</a>
		<a class="mui-tab-item" onclick="jumpToMarket()">
			<span class="mui-icon mui-icon-download"></span>
			<span class="mui-tab-label">库</span>
		</a>
<!-- 		<a class="mui-tab-item" onclick="jumpToMarket()">
			<span class="mui-icon mui-icon-download"></span>
			<span class="mui-tab-label">广场</span>
		</a> -->
<!-- 		<a class="mui-tab-item" onclick="jumpToCamera()">
			<span class="mui-icon mui-icon-camera"></span>
			<span class="mui-tab-label">拍</span>
		</a> -->
<!-- 		<a class="mui-tab-item" onclick="jumpToChat()">
			<span class="mui-icon mui-icon-chatbubble"></span>
			<span class="mui-tab-label">消息</span>
		</a> -->
		<a class="mui-tab-item mui-active" onclick="jumpToMy()">
			<span class="mui-icon mui-icon-contact"></span>
			<span class="mui-tab-label">我的</span>
		</a>
	</nav>
</body>
</html>

<script src="../js/mui.js"></script>
<script src="../js/mui.min.js"></script>
<script src="../js/app.js"></script>
<script type="text/javascript">
	function choosePhoto(event) {
		if (mui.os.plus) {
			var a = [{
					title: '拍照'
				}, {
				  title: '从手机相册选择'
				}];
			plus.nativeUI.actionSheet(
				{
					title: '修改头像',
					cancel: '取消',
					buttons: a
				}, function(b) {
					switch (b.index) {
						case 0:
							break;
						case 1: //拍照  
							getImages(event);
							break;
						case 2: //打开相册  
							galleryImages(event);
							break;
						default:
							break;
					}
				}, false);
		}
	}
	//拍照  
	function getImages(event) {
		var mobileCamera = plus.camera.getCamera();
		mobileCamera.captureImage(function(e) {
			plus.io.resolveLocalFileSystemURL(e, function(entry) {
				var path = entry.toLocalURL() + '?version=' + new Date().getTime();
				uploadHeadImg(path, event);
				mui.toast(path);
			}, function(err) {
				mui.toast("读取拍照文件错误");
			});
		}, function(e) {
			mui.toast("er", err);
		}, function() {
			filename: '_doc/head.png';
		});
	}
	//本地相册选择   
	function galleryImages(event) {
		mui.toast("你选择了从相册选择");
		plus.gallery.pick(function(a) {
			plus.io.resolveLocalFileSystemURL(a, function(entry) {
				plus.io.resolveLocalFileSystemURL('_doc/', function(root) {
					root.getFile('head.png', {}, function(file) {
						//文件已经存在
						file.remove(function() {
							mui.toast("文件移除成功");
							entry.copyTo(root, 'head.png', function(e) {
								var path = e.fullPath + '?version=' + new Date().getTime();
								uploadHeadImg(path, event);
							}, function(err) {
								mui.toast("copy image fail: ", err);
							});
						}, function(err) {
							mui.toast("删除图片失败：（" + JSON.stringify(err) + ")");
						});
					}, function(err) {
						//打开文件失败
						entry.copyTo(root, 'head.png', function(e) {
							var path = e.fullPath + '?version=' + new Date().getTime();
							uploadHeadImg(path, event);
						}, function(err) {
							mui.toast("上传图片失败：（" + JSON.stringify(err) + ")");
						});
					});
				}, function(e) {
					mui.toast("读取文件夹失败：（" + JSON.stringify(err) + ")");
				});
			});
		}, function(err) {
			mui.toast("读取拍照文件失败: ", err);
		}, {
			filter: 'image'
		});
	};
	/////////////////////////////////////
	//自动加载
	(function($, owner) {
		// 用户信息
		getUserInfo();
		// 统计
		getTotal();
	}(mui, window.app = {}));
	// 获取用户信息
	function getUserInfo(){
		// 判断用户登陆
		var userInfo = cacheGet(userInfoKey);
		if (!userInfo) {
			mui.toast('没有登陆',{ 
				duration:'short', type:'div',
			});
			setTimeout(function(){
				jumpToMyLogin();
			}, 500);
			return
		}
		// 用户信息
		var uname = getStrLimitNum(userInfo.name, 10);
		var udetail = getStrLimitNum(userInfo.detail, 10);
		mui("#uname")[0].innerHTML = uname;
		mui("#udetail")[0].innerHTML = udetail;
		if (userInfo.head!='') {
			mui("#uhead")[0].innerHTML = '<img src="'+userInfo.head+'">';
		}
	}
	// 获取点赞/收藏统计
	function getTotal(){
		// mui("#zanTotal")[0].innerHTML = cache.list.length;
		var indexList = getIndexCache();
		var marketList = getMarketCache();
		var resIndex = indexList.list;
		var resMarket = marketList.list;
		var zanTotal = 0;
		var collectTotal = 0;
		var plusTotal = 0;
		// mui.toast('??'+resIndex[0].zanTotal)
		if (resIndex.length > 0) {
			for (var i=0;i<resIndex.length;i++) {
				zanTotal = zanTotal * 1 + resIndex[i].zanTotal;
				collectTotal = collectTotal * 1 + resIndex[i].collectTotal;
			}
		}
		if (resMarket.length > 0) {
			for (var m=0;m<resMarket.length;m++) {
				zanTotal = zanTotal * 1 + resMarket[m].zanTotal;
				collectTotal = collectTotal * 1 + resMarket[m].collectTotal;
				plusTotal = plusTotal * 1 + resMarket[m].plusTotal;
			}
		}
		mui("#zanTotal")[0].innerHTML = zanTotal;
		mui("#collectTotal")[0].innerHTML = collectTotal;
		mui("#plusTotal")[0].innerHTML = plusTotal;
	}
	//获取首页数据缓存
	function getIndexCache(){
		var resList = cacheGet(indexList);
		if (!resList) {
			var list = new Array(),  //数据数组
				idstring = ''; //ID字符串集合
			return {
				// 数据数组
				list: list,
				// 历史ID集合
				idstr: idstring
			};
		}
		return resList;
	}
	//获取库数据缓存
	function getMarketCache(){
		var resList = cacheGet(marketList);
		if (!resList) {
			var list = new Array(),  //数据数组
				idstring = ''; //ID字符串集合
			return {
				// 数据数组
				list: list,
				// 历史ID集合
				idstr: idstring
			};
		}
		return resList;
	}
	// /** 
	//  * 图片处理
	//  * */ 
	// function choosePhoto(){
	// 	//弹出对话框
	// 	mui.confirm('','请选择方式',['上传','拍照','取消'],function (e) {
	// 		var way = e.index;
	// 		if (way==0) {
	// 			mui.toast('上传');
	// 			getAlbum();
	// 		} else if (way==1) {
	// 			mui.toast('拍照'); 
	// 			getImage();
	// 		} else {
	// 			mui.toast('取消');
	// 		}
	// 	},'div');
	// }
	// // 选择图片
	// function getAlbum(){ 
	// 	plus.gallery.pick(function(path){
	// 		// mui.toast(path);
	// 		// mui("#path")[0].innerHTML = path;
	// 		// mui("#uHead")[0].innerHTML = '<img src="'+path+'">';
	// 		mui.toast(path.width)
	// 		var filePath = getBase64Image(path);
	// 		mui.toast(filePath); return
	// 		setUpload(path);
	// 	}, function(e){
	// 		outSet('取消选择图片');
	// 	}, {filter:'image'});
	// }
	// // 拍照读取
	// function getImage(){
	// 	var cmr = plus.camera.getCamera();
	// 	cmr.captureImage(function(p){
	// 		plus.io.resolveLocalFileSystemURL(p, function(entry){
	// 			// createItem(entry);
	// 			plus.nativeUI.showWaiting("拍照中", ""); 
	// 			var path = entry.toLocalURL();
	// 			// mui.toast(path);
	// 			// mui("#uHeadBg")[0].innerHTML = '<img src="'+path+'">';
	// 			var filePath = getBase64Image(path);
	// 			// mui.toast(filePath);
	// 			setUpload(filePath);
	// 		}, function(e){
	// 			mui.toast('读取拍照文件错误：'+e.message,{ duration:'long', type:'div' });
	// 		});
	// 	}, function(e){
	// 	}, {filename:'_doc/camera/',index:1});
	// }
	// // 上传图片
	// function setUpload(path){
	// 	// 系统参数
	// 	var sys = getSys();
	// 	// 用户信息
	// 	var userInfo = cacheGet(userInfoKey);
	// 	var uid = userInfo ? userInfo.uid : 0;
	// 	mui.toast('user：'+path); return
	// 	mui.ajax(sys.domain+'/app/user/head',{
	// 		data:{
	// 			appAccess: sys.appAccess,
	// 			uid:uid,
	// 			file:path
	// 		},
	// 		dataType:'json', //服务器返回json格式数据
	// 		type:'post', //HTTP请求类型
	// 		timeout:10000, //超时时间设置为10秒
	// 		headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
	// 		success:function(res){
	// 			mui.toast('res'+res.code); return
	// 			if (res.code==-1) {
	// 				mui.toast('需要更新系统参数？',{ 
	// 					duration:'long', type:'div',
	// 				});
	// 				setTimeout(function(){
	// 					setSys();
	// 					jumpToIndex();
	// 				},500);
	// 				return
	// 			} else if (res.code!=0) {
	// 				mui.toast('上传失败');
	// 				return
	// 			}
	// 			mui.toast('OK')
	// 		},
	// 		error:function(xhr,type,errorThrown){
	// 			mui.toast('网络错误！',{ 
	// 				duration:'short', type:'div',
	// 			});
	// 		}
	// 	});
	// }
	// //将图片压缩转成base64 
	// function getBase64Image(img) {
	// 	var canvas = document.createElement("canvas");
	// 	var width = img.width;
	// 	var height = img.height;
	// 	if(width > 1000){
	// 		height=height/1.5;
	// 		width=width/1.5;
	// 	}
		
	// 	if(height > 1000){
	// 		height=height/1.5;
	// 		width=width/1.5;
	// 	}
		
	// 	canvas.width = width; /*设置新的图片的宽度*/
	// 	canvas.height = height; /*设置新的图片的长度*/
	// 	var ctx = canvas.getContext("2d");
	// 	ctx.drawImage(img, 0, 0, width, height); /*绘图*/
	// 	var dataURL = canvas.toDataURL("image/png", 1);
	// 	return dataURL.replace("data:image/png;base64,", "");
	// }
	// mui.init();
	// document.getElementById("uHead").addEventListener("tap", function() {
	// 	var editButtons = new Array();
	// 	editButtons.push({
	// 		title: "拍照上传",
	// 		style: "default"
	// 	});
	// 	editButtons.push({
	// 		title: "从相册选择",
	// 		style: "default"
	// 	});
	// 	plus.nativeUI.actionSheet({
	// 		cancel: "取消",
	// 		buttons: editButtons
	// 	}, function(e) {
	// 		var index = e.index;
	// 		switch(index) {
	// 			case 1:
	// 				mui.toast('拍照');
	// 				// captureImage(); //拍照
	// 				break;
	// 			case 2:
	// 				mui.toast('相册');
	// 				selectImage(); //相册选择
	// 				break;
	// 		}
	// 	});
	// });
	//选择图片
	// function selectImage() {
		// plus.gallery.pick(function(e) {
		// 	// //确定选择图片
		// 	// mui.toast(path.files[0]); return
		// 	// // uploadPicture(path.url);
		// 	for(var i in e.files){
		// 		uploadPicture(e.files[i]); 
		// 	}
		// }, function(e) {
		// 	mui.toast("没有选择图片");
		// }, {
		// 	filter: 'image',
		// 	multiple: true,
		// 	system: false
		// });
		// // 系统参数
		// var sys = getSys();
		// // 用户信息
		// var userInfo = cacheGet(userInfoKey);
		// var uid = userInfo ? userInfo.uid : 0;
		// mui.toast(uid)
		// plus.gallery.pick(
		// 	function(path){
		// 		// mui("#pathUrl")[0].innerHTML = path;
		// 		var task = plus.uploader.createUpload(
		// 			sys.domain+'/app/user/head',
		// 			{ method:"POST",blocksize:204800,priority:100 },
		// 			function (t,status){
		// 				// mui("#pathUrl")[0].innerHTML = JSON.stringify(t);
		// 			   // mui.toast(JSON.stringify(t));
		// 			   // mui.toast(status);
		// 			   if (status == 200) { 
		// 					mui("#pathUrl")[0].innerHTML = t.responseText;
		// 					mui.toast("success:"+t.responseText);
		// 				} else {
		// 					mui("#pathUrl")[0].innerHTML = status;
		// 					mui.toast("failed:"+status);
		// 				}
		// 			}
		// 		);
		// 		task.addData("uid", uid);
		// 		task.addFile(path, {key:path});
		// 		task.start();
		// 	},
		// 	function(e){mui.toast('取消了选择');}
		// );
	// }
	// //上传图片 
	// function uploadPicture(path) {
	// 	// 系统参数
	// 	var sys = getSys();
	// 	// 用户信息
	// 	var userInfo = cacheGet(userInfoKey);
	// 	var uid = userInfo ? userInfo.uid : 0;
	// 	// // 图片资源
	// 	// var image = new Image();
	// 	// image.src = path;
	// 	// // mui.toast('imgData：'+image); return
	// 	// var imgData = getBase64Image(image);
	// 	// mui.toast('imgData：'+uid+'，'+path); return
	// 	mui("#pathUrl")[0].innerHTML = uid+'，'+path; return
	// 	var sendData = {
	// 		appAccess: sys.appAccess,
	// 		uid: uid,
	// 		file: path
	// 	}
	// 	mui.ajax(sys.domain+'/app/user/head', {
	// 		type: 'POST',
	// 		dataType: 'json',
	// 		data: sendData,
	// 		async: true,
	// 		timeout: 100000, //超时时间设置为10秒；
	// 		success: function(res) {
	// 			mui.toast('res'+res.code); return
	// 			if (res.code==-1) {
	// 				mui.toast('需要更新系统参数？',{ 
	// 					duration:'long', type:'div',
	// 				});
	// 				setTimeout(function(){
	// 					setSys();
	// 					jumpToIndex();
	// 				},500);
	// 				return
	// 			} else if (res.code!=0) {
	// 				mui.toast('上传失败');
	// 				return
	// 			}
	// 			mui.toast('OK')
	// 		},
	// 		error:function(xhr,type,errorThrown){
	// 			mui.toast('网络错误！',{ 
	// 				duration:'short', type:'div',
	// 			});
	// 		}
	// 	});
	// }
	// //将图片压缩转成base64 
	// function getBase64Image(img) {
	// 	var canvas = document.createElement("canvas");
	// 	canvas.width = img.width;
	// 	canvas.height = img.height;
	// 	var ctx = canvas.getContext("2d");
	// 	ctx.clearRect(0, 0, canvas.width, canvas.height);
	// 	ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
	// 	return canvas.toDataURL("image/png", 0.8);
	// }
	
	// 定位测试
	function setSign(){
		mui.plusReady(function() {
			plus.geolocation.getCurrentPosition(translatePoint,function(e){
				mui.toast("异常:" + e.message);
	        });
		});
	}
	 function translatePoint(position){
	    var currentLon = position.coords.longitude;
	    var currentLat = position.coords.latitude;
	    mui.toast(currentLon);
		//书写自己的逻辑
	}
</script>